//
//  MessageServiceProviderController.m
//  BigToBig
//
//  Created by yi liu on 16/8/15.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "MessageServiceProviderController.h"
#import "MessageServiceProviderChooseCell.h"
#import "ChooseTableViewCell.h"
@interface MessageServiceProviderController ()
<
    UITableViewDelegate,
    UITableViewDataSource,
    MessageServiceProviderChooseCellDelegate
>

@property (nonatomic , assign)NSInteger typeSelected;
@property (nonatomic , assign)NSInteger renzhengSelected;
@property (nonatomic , assign)BOOL isSureButtonSelected;
@property (nonatomic , strong)UITableView *mainTableView;

@end

@implementation MessageServiceProviderController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = @"申请投资人";
    titleLab.textColor = [UIColor whiteColor];
    [self setBackBar];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    
    self.navigationController.navigationBar.translucent = NO;
    
    self.navigationController.navigationBar.barTintColor = COLOR_RGBA(77, 155, 255, 1);
    
    self.mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    [self.view addSubview:self.mainTableView];
    self.mainTableView.showsVerticalScrollIndicator = NO;
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    [self.mainTableView registerClass:[MessageServiceProviderChooseCell class] forCellReuseIdentifier:NSStringFromClass([MessageServiceProviderChooseCell class])];
    [self.mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass( [UITableViewCell class])];
    
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor colorWithWhite:0.949 alpha:1.000];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = [UIColor grayColor];
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont systemFontOfSize:11];
    [view addSubview:titleLabel];
    
    if (section == 1) {
        view.frame = CGRectMake(0, 0, kScreenWidth, 50);
        titleLabel.frame = CGRectMake(10, 0, kScreenWidth - 20, 50);
        titleLabel.text = @"请上传清晰证件正反面,最多上传二张图片,上传图片格式为(JPG、PNG)，上传文件小于5MB";
    }
    if (section == 2) {
    
        UIButton *sure = [UIButton buttonWithType:UIButtonTypeCustom];
        sure.selected = self.isSureButtonSelected;
        sure.frame = CGRectMake(10, 10, 25, 25);
        [view addSubview:sure];
        [sure setImage:[UIImage imageNamed:@"xuanzhong"] forState:UIControlStateSelected];
        [sure setImage:[UIImage imageNamed:@"weixuanzhong"] forState:UIControlStateNormal];
        [sure addTarget:self action:@selector(time1:) forControlEvents:UIControlEventTouchUpInside];
        UILabel *word = [[UILabel alloc] initWithFrame:CGRectMake(sure.maxX, 10, kScreenWidth - 50, 50)];
        word.text = @"我承诺以上所有登记的内容都是绝对真实的,并对因一切虚假信息产生的后果负全责,我已了解和同意《大秀创投提供的服务》以及《大秀创投创业融资服务协议》.";
        word.textColor = [UIColor lightGrayColor];
        word.font = [UIFont systemFontOfSize:11];
        word.numberOfLines = 0;
        [view addSubview:word];
    }
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0 || section == 5) {
        return 0.001f;
    }
    return 40;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 2;
    }if (section == 1) {
        return 3;
    }
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    // 定义cell标识  每个cell对应一个自己的标识
    NSString *CellIdentifier = [NSString stringWithFormat:@"cell%ld%ld",indexPath.section,indexPath.row];
    
    //     NSString *CellIdentifier1 = [NSString stringWithFormat:@"pcell%ld%ld",indexPath.section,indexPath.row];
    //
    //    NSString *CellIdentifier2 = [NSString stringWithFormat:@"lcell%ld%ld",indexPath.section,indexPath.row];
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            MessageServiceProviderChooseCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            
            cell = [[MessageServiceProviderChooseCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
            cell.isSelected = self.typeSelected;
            cell.textLabel.text = @"类型";
            cell.firstLabel.text = @"个人";
            cell.secondLabel.text = @"公司";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.messageServiceProviderChooseCellDelegate = self;
            return cell;
        }
        if (indexPath.row == 1) {
            MessageServiceProviderChooseCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            
            cell = [[MessageServiceProviderChooseCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
            cell.isSelected = self.typeSelected;
            cell.textLabel.text = @"是否认证";
            cell.firstLabel.text = @"认证";
            cell.secondLabel.text = @"不认证";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.messageServiceProviderChooseCellDelegate = self;
            return cell;
        }
    }
    
    

    
    ChooseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    cell = [[ChooseTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    

    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            cell.leftLab.text = @"姓名";
            cell.rightLab.text = @"请填写";
        }
        if (indexPath.row == 1) {
            cell.leftLab.text = @"区域";
            cell.rightLab.text = @"请填写";
        }
        if (indexPath.row == 2) {
            cell.leftLab.text = @"上传身份证";
            cell.rightLab.text = @"请点击上传";
        }
        
    }if (indexPath.section == 2) {
        cell.leftLab.text = @"备注信息";
        cell.rightLab.text = @"请填写信息";
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}


//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    AlbumViewController *albumVC = [[AlbumViewController alloc]init];
//    albumVC.allowSelectCount = 2;
//    [self.navigationController pushViewController:albumVC animated:YES];
//}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (void)changeSelectedWithSelected:(NSInteger)selected title:(NSString *)titleString{
    if ([titleString isEqualToString:@"类型"]) {
        self.typeSelected = selected;

    }else{
        self.renzhengSelected = selected;
    }
}
- (void)time1:(UIButton *)btn{
    btn.selected = !btn.selected;
    self.isSureButtonSelected = btn.selected;
}

- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 20, 44);
    [backBtn addTarget:self action:@selector(backController) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    BackButton *saveBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake(kScreenWidth - 44,0 , 44, 44);
    [saveBtn addTarget:self action:@selector(SaveMessage) forControlEvents:UIControlEventTouchUpInside];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn setTitle:@"提交" forState:UIControlStateNormal];
    [saveBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:saveBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
}

- (void)SaveMessage{
    
}

- (void)backController{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


@end
